<template>
    <div>
    <h1>病房信息添加</h1>
    <table class="table">
        <thead>
            <tr>
                <td>病房号</td>
                <td>
                   <input type="text" v-model="data.rid">
                </td>
            </tr>
            <tr>
                <td>病房名称</td>
                <td>
                    <input type="text" v-model="data.name">
                </td>
            </tr>
            <tr>
                <td>所属科室</td>
                <td>
                    <select v-model="data.cid">
                        <option value="0">请选择</option>
                        <option v-for="a in swert"  :value="a.cid">{{ a.name }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>床位总数量</td>
                <td>
                    <input type="text" v-model="data.num">
                </td>
            </tr>
            <tr>
                <td>默认状态</td>
                <td>
                    <input type="checkbox" v-model="data.mstart">默认为未满
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="checkbox" v-model="data.start">选中为维修，不选中为启用
                </td>
            </tr>
            <tr>
                <td>空闲床数量</td>
                <td>
                    <input type="text" v-model="data.knum">
                </td>
            </tr>
            <tr>
                <td>创建日期</td>
                <td>
                    <input type="date" v-model="data.createTime">
                </td>
            </tr>
            <tr>
                
                <td colspan="2">
                    <input type="button" value="添加" @click="Add">
                </td>
            </tr>
        </thead>
    </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import moment from "moment";
const data=ref({
    "id": 0,
  "rid": "",
  "cid": 0,
  "num": 0,
  "start": true,
  "mstart": true,
  "knum": 0,
  "createTime": "2025-05-19T02:22:09.240Z",
  "name": ""
})
onMounted(()=>{
    Xiala()
})
const swert=ref([{
    "cid": 1,
    "name": "内科",
}])
const Xiala=()=>{
    axios.get("https://localhost:7140/api/Room/Xiala").then(res=>{
        swert.value=res.data
    })
}
const Add=()=>{
    if(data.value.name==""){
        alert('病房名称不能为空');
        return;
    }
    if(data.value.name.length>6){
        alert('病房名称不能超过6个字符');
        return;
    }
    axios.post("https://localhost:7140/api/Room/AddAsync",data.value).then(res=>{
    if(res.data>0){
        alert('添加成功');
        location.href='/ShowRoomView';
    }
    else{
        alert('添加失败');
    }
    })
}
</script>

<style scoped>

</style>